@extends('layouts.app')
@section('content')
@php
    use Illuminate\Support\Facades\Auth;
    use App\Modules\User\Models\Admin;
    $user = Auth::user();
@endphp
    <div class="content">
        <div class="row custom-invoice">
            <div>
                <form class="form form-inline" method="get" action="{{ route('admin.goods_gift.index') }}" autocomplete="off">
                    <div class="form-group">
                        <input class="form-control" type="text" name="title" id="" value="{{ $title }}"
                               placeholder="输入名称">
                    </div>
                    <div class="form-group">
                        <select class="form-control select2" name="shop_id" id="shop_id">
                            @if ($shopId != '')
                                <option value="{{$shopId}}">{{$shopName}}</option>
                            @else
                                <option value="0">选择门店</option>
                            @endif
                        </select>
                    </div>
                    <button type="submit" class="btn btn-success" value="">搜索</button>
                </form>
            </div>
            {{-- @can('shop-edit') --}}
            {{-- <a class="btn btn-success" href="{{ route("admin.goods_gift.create") }}">添加</a> --}}
            {{-- @endcan --}}

            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                @can('staff_goods_gift-add')
                    <a class="btn btn-success" style="margin-top: 15px" href="{{ route("admin.goods_gift.create") }}">添加</a>
                @endcan
            @else
                @can('goods_gift-add')
                    <a class="btn btn-success" style="margin-top: 15px" href="{{ route("admin.goods_gift.create") }}">添加</a>
                @endcan
            @endif
            <br />
            <br />
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>赠送礼包名</th>
                    <th>所属门店</th>
                    <th>包含产品</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <td>{{ $item->title }}</td>
                        <td>{{ $item->shop_name }}</td>
                        <td>{!! $item->content !!}</td>
                        <td>
                            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                @can('staff_goods_gift-edit')
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.goods_gift.edit', ['goods_gift' => $item->id]) }}"><i class="fa fa-edit"></i> 编辑</a>
                                @endcan
                            @else
                                @can("goods_gift-edit")
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.goods_gift.edit', ['goods_gift' => $item->id]) }}"><i class="fa fa-edit"></i> 编辑</a>
                                @endcan
                            @endif
                            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                @can('staff_goods_gift-delete')
                                    <a class="btn btn-danger btn-xs delete-confirm" data-href="{{ route('admin.goods_gift.destroy', ['goods_gift' => $item->id]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                                @endcan
                            @else
                                @can("goods_gift-delete")
                                    <a class="btn btn-danger btn-xs delete-confirm" data-href="{{ route('admin.goods_gift.destroy', ['goods_gift' => $item->id]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                                @endcan
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->appends(['title' => $title, 'shop_id' => $shopId])->links() }}
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $(".select2#shop_id").select2({
            width:"250px",
            ajax: {
                dataType: 'json',
                delay: 250,
                url: function () {
                    return '{{ route('admin.goods_gift.search_shops') }}';
                },
                processResults: function (data) {
                    return {
                        results: $.map(data, function (row, key) {
                            return {
                                id: key,
                                text: row,
                            };
                        })
                    };
                }
            }
        });
    </script>
@endpush
